<template>
  <!-- 屈光检查 -->
  <el-form inline :model="dataForm" :rules="dataRule" ref="refractiveForm">
    <el-row class="bg-row">
      <el-form-item label="验光号">
        <el-input v-model="checkData.checkNumber" readonly></el-input>
      </el-form-item>
      <el-form-item label="验光师">
        <el-input v-model="checkData.checker" readonly></el-input>
      </el-form-item>
      <el-form-item label="日期">
        <el-input v-model="checkData.checkDate" readonly></el-input>
      </el-form-item>
    </el-row>
    <el-row class="bg-row">
      <el-form-item label="卡号" v-if="customerData.cardNum">
        <el-input v-model="customerData.cardNum" @keyup.enter.native="getCustomerByCardNo()"></el-input>
      </el-form-item>
      <el-form-item label="卡号" v-else>
        <el-input v-model="customerData.uniqueCode"></el-input>
      </el-form-item>
      <el-form-item label-width="0">
        <el-button type="primary" @click="openDialog('customer')">查询</el-button>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input class="width-125" v-model="customerData.name" readonly></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-input class="width-125" v-if="customerData.gender == 0" value="男" readonly></el-input>
        <el-input class="width-125" v-if="customerData.gender == 1" value="女" readonly></el-input>
      </el-form-item>
      <el-form-item label="生日">
        <el-input class="width-125" v-model="customerData.birthDay" readonly></el-input>
      </el-form-item>
      <el-form-item label="电话">
        <el-input class="width-125" v-model="customerData.telPhone" readonly></el-input>
      </el-form-item>
      <el-form-item label-width="0">
        <el-button type="info" @click="openDialog('customerDetail')">详情</el-button>
      </el-form-item>
    </el-row>

    <!-- 一般资料 begin -->
    <el-divider content-position="left">一般资料</el-divider>
   <!-- <el-row class="bg-row">
        <el-form-item label="原配镜类型">
          <el-select v-model="dataForm.glassesType">
            <el-option v-for="item in glassesTypeOption" :value="item.value" :label="item.label" :key="item.value"></el-option>
          </el-select>
        </el-form-item>
    </el-row>
    <el-row class="bg-row">
      <el-form-item label="镜片材质">
        <el-select v-model="dataForm.glassesM">
          <el-option v-for="item in bizData.glassmaterialsData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="镜片类型">
        <el-select v-model="dataForm.glassesKind">
          <el-option v-for="item in bizData.glassesKind" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="镜片颜色">
        <el-select v-model="dataForm.glassesColor">
          <el-option v-for="item in bizData.glassColor" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="戴镜年限">
        <el-input class="width-125" v-model="dataForm.glassesAge">
          <template slot="append">年</template>
        </el-input>
      </el-form-item>
    </el-row>
    <el-row class="bg-row">
      <el-form-item label="隐形材质">
        <el-select v-model="dataForm.contactLensm">
          <el-option v-for="item in bizData.contactLensm" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="隐形产品">
        <el-select v-model="dataForm.contactLensBrand">
          <el-option v-for="item in bizData.contactLensBrand" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="镜片颜色">
        <el-select v-model="dataForm.contactLensColor">
          <el-option v-for="item in bizData.contactLensColor" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="戴镜年限">
        <el-input class="width-125" v-model="dataForm.contactLensAge">
          <template slot="append">年</template>
        </el-input>
      </el-form-item>
    </el-row>-->
    <el-row class="bg-row">
      <el-form-item class="miui-textarea" label="主诉" style="width: 100%;">
        <el-input type="textarea" v-model="dataForm.customerSay" style="width: 100%;"></el-input>
      </el-form-item>
    </el-row>
    <el-row class="bg-row">
    	<el-form-item label="现病史" class="miui-textarea" style="width: 100%;">
    		<el-input  v-model="dataForm.diseaseHistory" ></el-input>
    	</el-form-item>
    </el-row>
    <!--<el-row class="bg-row">
    	<el-form-item label="过敏史" class="miui-textarea" style="width: 100%;">
    		<el-input v-model="dataForm.allergyHistory" ></el-input>
    	</el-form-item>
    </el-row>
    <el-row class="bg-row">
    	<el-form-item label="手术史" class="miui-textarea" style="width: 100%;">
    		<el-input  v-model="dataForm.operationHistory"></el-input>
    	</el-form-item>
    </el-row>
    <el-row class="bg-row">
    	<el-form-item label="家族史" class="miui-textarea" style="width: 100%;">
    		<el-input  v-model="dataForm.familyHistory"s></el-input>
    	</el-form-item>
    </el-row>-->
    <el-row class="bg-row">
      <el-form-item label="既往史" class="miui-textarea" style="width: 100%;">
        <el-input  v-model="dataForm.otherHistory"></el-input>
      </el-form-item>
    </el-row>
    <el-row class="bg-row">
    	<el-col :span="6">
    		<el-form-item label="父亲近视史">
    			<el-select v-model="dataForm.fatherHistory">
    				<el-option v-for="myopiaItem in bizData.myopiaHistory" :value="myopiaItem.value" :label="myopiaItem.label" :key="myopiaItem.value"></el-option>
    			</el-select>
    		</el-form-item>
    	</el-col>
    	<el-col :span="18">
    		<el-form-item label="父亲近视史描述" class="miui-textarea" style="width: 100%;">
    		  <el-input v-model="dataForm.fatherHistoryDesc" :disabled="!dataForm.fatherHistory || dataForm.fatherHistory == '1'"></el-input>
    		</el-form-item>
    	</el-col>
    </el-row>
    <el-row class="bg-row">
      <el-col :span="6">
        <el-form-item label="母亲近视史">
          <el-select v-model="dataForm.motherHistory">
            <el-option v-for="myopiaItem in bizData.myopiaHistory" :value="myopiaItem.value" :label="myopiaItem.label" :key="myopiaItem.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    	<el-col :span="18">
        <el-form-item label="母亲近视史描述" class="miui-textarea" style="width: 100%;">
          <el-input v-model="dataForm.motherHistoryDesc" :disabled="!dataForm.motherHistory || dataForm.motherHistory == '1'"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <!-- 一般资料 end -->

    <!-- 体格检查 begin -->
    <el-divider content-position="left">眼睛健康评估</el-divider>
    <table class="miui-table">
      <tr>
        <td class="miui-table-label">身高</td>
        <td class="text-left">
          <el-input class="input-width-217" v-model="dataForm.height" placeholder="身高"><span slot="append">CM</span></el-input>
        </td>
        <td class="miui-table-label">体重</td>
        <td class="text-left">
          <el-input class="input-width-217" v-model="dataForm.weight" placeholder="体重"><span slot="append">KG</span></el-input>
        </td>
        <td class="miui-table-label">体温</td>
        <td class="text-left">
          <el-input class="input-width-217" v-model="dataForm.temperature" placeholder="体温"><span slot="append">°C</span></el-input>
        </td>
      </tr>
    </table>
    <table class="miui-table">
      <tr>
        <td class="miui-table-label" style="width: 60px;"></td>
        <td class="miui-table-label">眼前段及眼附属器</td>
        <td class="miui-table-label">眼底检查</td>
      </tr>
      <tr>
        <td class="miui-table-label" style="width: 60px;">右眼</td>
        <td style="text-align: left;margin-left: 15px;">
          <el-radio-group v-model="dataForm.frontOd">
            <el-radio :label="0">正常</el-radio>
            <el-radio :label="1">异常发现</el-radio>
          </el-radio-group>
          <el-input class="input-width-217" style="margin-left: 15px;" v-if="dataForm.frontOd == 1" v-model="dataForm.frontOdText"></el-input>
        </td>
        <td class="text-left">
          <el-radio-group style="margin-right: 15px;" v-model="dataForm.fundusOd" >
            <el-radio :label="0">正常</el-radio>
            <el-radio :label="1">异常发现</el-radio>
          </el-radio-group>
          <el-autocomplete v-if="dataForm.fundusOd == 1" class="inline-input" v-model="dataForm.fundusOdText" :fetch-suggestions="querySearch"></el-autocomplete>
        </td>
      </tr>
      <tr>
        <td class="miui-table-label" style="width: 60px;">左眼</td>
        <td style="text-align: left;margin-left: 15px;">
          <el-radio-group v-model="dataForm.frontOs">
            <el-radio :label="0">正常</el-radio>
            <el-radio :label="1">异常发现</el-radio>
          </el-radio-group>
          <el-input class="input-width-217" style="margin-left: 15px;" v-if="dataForm.frontOs == 1" v-model="dataForm.frontOsText"></el-input>
        </td>
        <td class="text-left">
          <el-radio-group style="margin-right: 15px;" v-model="dataForm.fundusOs">
            <el-radio :label="0">正常</el-radio>
            <el-radio :label="1">异常发现</el-radio>
          </el-radio-group>
          <el-autocomplete v-if="dataForm.fundusOs == 1" class="inline-input" v-model="dataForm.fundusOsText" :fetch-suggestions="querySearch"></el-autocomplete>
        </td>
      </tr>
    </table>
    <table class="miui-table">
      <tr>
        <td class="miui-table-label">眼位</td>
        <td class="text-left">
          <el-radio-group v-model="dataForm.eyePosition" style="margin-right: 15px">
            <el-radio label="0">正位</el-radio>
            <el-radio label="1">隐斜</el-radio>
            <el-radio label="2">显斜</el-radio>
          </el-radio-group>
          <el-input class="input-width-217" v-if="dataForm.eyePosition == 1" v-model="dataForm.eyePositionText"
            placeholder="隐斜现象"></el-input>
          <el-input class="input-width-217" v-if="dataForm.eyePosition == 2" v-model="dataForm.eyePositionText"
            placeholder="显斜现象"></el-input>
        </td>
        <td class="miui-table-label">集合近点(NPC)</td>
        <td class="text-left">
          <el-input class="input-width-217" v-model="dataForm.nearPoint" placeholder="集合近点"><span slot="append">cm</span></el-input>
        </td>
      </tr>
    </table>
    <!-- 体格检查 end -->

    <el-divider content-position="left">旧镜信息</el-divider>
    <table class="miui-table">
      <tr>
        <td width="50px"></td>
        <td>球镜</td>
        <td>柱镜</td>
        <td>轴向</td>
        <td>曲率</td>
        <td>直径</td>
        <td>三棱镜</td>
        <td>Add</td>
        <td>基底</td>
        <td>瞳距(mm)</td>
        <td>VA</td>
      </tr>
      <tr>
        <td>OD</td>
        <td>
          <el-form-item prop="ballOd">
            <el-input v-model="dataForm.ballOd"></el-input>
          </el-form-item>

        </td>
        <td>
          <el-form-item prop="postOd">
            <el-input v-model="dataForm.postOd"></el-input>
          </el-form-item>

        </td>
        <td>
          <el-form-item prop="axesOd">
            <el-input v-model="dataForm.axesOd"></el-input>
          </el-form-item>

        </td>
        <td><el-input v-model="dataForm.diameterOd"></el-input></td>
        <td><el-input v-model="dataForm.camberOd"></el-input></td>
        <td><el-input v-model="dataForm.arriseOd"></el-input></td>
        <td><el-input v-model="dataForm.addOd"></el-input></td>
        <td><el-input v-model="dataForm.basisOd"></el-input></td>
        <td><el-input v-model="dataForm.interHighOd"></el-input></td>
        <td><el-input v-model="dataForm.vaOd"></el-input></td>

      </tr>
      <tr>
        <td>OS</td>
        <td>
          <el-form-item prop="ballOs">
            <el-input v-model="dataForm.ballOs"></el-input>
          </el-form-item>
        </td>
        <td>
          <el-form-item prop="postOs">
            <el-input v-model="dataForm.postOs"></el-input>
          </el-form-item>
        </td>
        <td>
          <el-form-item prop="axesOs">
            <el-input v-model="dataForm.axesOs"></el-input>
          </el-form-item>
        </td>
        <td><el-input v-model="dataForm.diameterOs"></el-input></td>
        <td><el-input v-model="dataForm.camberOs"></el-input></td>
        <td><el-input v-model="dataForm.arriseOs"></el-input></td>
        <td><el-input v-model="dataForm.addOs"></el-input></td>
        <td><el-input v-model="dataForm.basisOs"></el-input></td>
        <td><el-input v-model="dataForm.interHighOs"></el-input></td>
        <td><el-input v-model="dataForm.vaOs"></el-input></td>

      </tr>
    </table>

    <el-divider content-position="left">屈光检查</el-divider>
    <el-row class="bg-row">
      <el-form-item label="主导眼">
        <el-select v-model="dataForm.leadingEye">
          <el-option v-for="item in bizData.leadingEyeData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="裸视力">
        <el-form-item label="OD(右)">
          <el-input v-model="dataForm.nakedOd"></el-input>
        </el-form-item>
        <el-form-item label="OS(左)">
          <el-input v-model="dataForm.nakedOs"></el-input>
        </el-form-item>
      </el-form-item>
    </el-row>
    <el-divider content-position="left">散瞳验光</el-divider>

      <table class="miui-table">
        <tr>
          <td :colspan="9">
            <el-form-item label-width="0">
              <el-radio-group v-model="dataForm.diffusePupil">
                <el-radio v-for="item in bizData.diffusePupilData" :label="item.value" :key="item.value">{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td width="50px"></td>
          <td>球镜</td>
          <td>柱镜</td>
          <td>轴向</td>
          <td></td>
          <td>球镜</td>
          <td>柱镜</td>
          <td>轴向</td>
          <td>VA</td>
        </tr>
        <tr>
          <td>OD</td>
          <td>
            <el-form-item prop="checkBallGlassOd" label-width="0">
              <el-input v-model="dataForm.checkBallGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="checkPostGlassOd" label-width="0">
              <el-input v-model="dataForm.checkPostGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="checkAxesOd" label-width="0">
              <el-input v-model="dataForm.checkAxesOd"></el-input>
            </el-form-item>
          </td>
          <td :rowspan="2">试镜</td>
          <td>
            <el-form-item prop="testBallGlassOd" label-width="0">
              <el-input v-model="dataForm.testBallGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="testPostGlassOd" label-width="0">
              <el-input v-model="dataForm.testPostGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="testAxesOd" label-width="0">
              <el-input v-model="dataForm.testAxesOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-input v-model="dataForm.testVaOd"></el-input>
          </td>
        </tr>
        <tr>
          <td>OS</td>
          <td>
            <el-form-item prop="checkBallGlassOs" label-width="0">
              <el-input v-model="dataForm.checkBallGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="checkPostGlassOs" label-width="0">
              <el-input v-model="dataForm.checkPostGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="checkAxesOs" label-width="0">
              <el-input v-model="dataForm.checkAxesOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="testBallGlassOs" label-width="0">
              <el-input v-model="dataForm.testBallGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="testPostGlassOs" label-width="0">
              <el-input v-model="dataForm.testPostGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="testAxesOs" label-width="0">
              <el-input v-model="dataForm.testAxesOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-input v-model="dataForm.testVaOs"></el-input>
          </td>
        </tr>
        <tr>
          <td :colspan="8"></td>
          <td>
            <el-button size="mini">检影</el-button>
          </td>
        </tr>
      </table>
    <el-divider content-position="left">主觉验光</el-divider>
      <table class="miui-table">
        <tr>
          <td width="50px"></td>
          <td>球镜</td>
          <td>柱镜</td>
          <td>轴向</td>
          <td>VA</td>
        </tr>
        <tr>
          <td>OD</td>
          <td>
            <el-form-item prop="oaBallGlassOd" label-width="0">
              <el-input v-model="dataForm.oaBallGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="oaPostGlassOd" label-width="0">
              <el-input v-model="dataForm.oaPostGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="oaAxesOd" label-width="0">
              <el-input v-model="dataForm.oaAxesOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-input v-model="dataForm.oaVaOd"></el-input>
          </td>
        </tr>
        <tr>
          <td>OS</td>
          <td>
            <el-form-item prop="oaBallGlassOs" label-width="0">
              <el-input v-model="dataForm.oaBallGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="oaPostGlassOs" label-width="0">
              <el-input v-model="dataForm.oaPostGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="oaAxesOs" label-width="0">
              <el-input v-model="dataForm.oaAxesOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-input v-model="dataForm.oaVaOs"></el-input>
          </td>
        </tr>
        <tr>
          <td :colspan="4"></td>
          <td>
            <el-button size="mini">主觉验光</el-button>
          </td>
        </tr>
      </table>

    <el-divider content-position="left">双眼平衡结果 <span style="color: red;">*</span></el-divider>
      <table class="miui-table">
        <tr>
          <td colspan="11" style="text-align: left;">
            <el-form-item label="验光类型" >
              <el-select v-model="dataForm.goals" clearable>
                <el-option v-for="item in optOptions" :value="item.value" :label="item.label" :key="item.value"></el-option>
              </el-select>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td width="50px"></td>
          <td>球镜</td>
          <td>柱镜</td>
          <td>轴向</td>
          <td>三棱镜</td>
          <td>基底</td>
          <td>远用瞳距(mm)</td>
          <td>近用瞳距(mm)</td>
          <td>瞳高</td>
          <td>VA</td>
          <td>Add</td>
        </tr>
        <tr>
          <td>OD</td>
          <td>
            <el-form-item prop="balBallGlassOd">
              <el-input v-model="dataForm.balBallGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balPostGlassOd">
              <el-input v-model="dataForm.balPostGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balAxesOd">
              <el-input v-model="dataForm.balAxesOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balArriseGlassOd">
              <el-input v-model="dataForm.balArriseGlassOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balBasisOd">
              <el-select size="mini" v-model="dataForm.balBasisOd">
                <el-option v-for="item in bizData.basalTypeData" :value="item.value" :label="item.label" :key="item.value"></el-option>
              </el-select>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balInterHighOd">
              <el-input v-model="dataForm.balInterHighOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balInterDistanceOd">
              <el-input v-model="dataForm.balInterDistanceOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="pupilHeightOd">
              <el-input v-model="dataForm.pupilHeightOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balVaOd">
              <el-input v-model="dataForm.balVaOd"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="addOd">
              <el-input v-model="dataForm.addOd"></el-input>
            </el-form-item>
          </td>
        </tr>
        <tr>
          <td>OS</td>
          <td>
            <el-form-item prop="balBallGlassOs">
              <el-input v-model="dataForm.balBallGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balPostGlassOs">
              <el-input v-model="dataForm.balPostGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balAxesOs">
              <el-input v-model="dataForm.balAxesOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balArriseGlassOs">
              <el-input v-model="dataForm.balArriseGlassOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balBasisOs">
              <el-select size="mini" v-model="dataForm.balBasisOs">
                <el-option v-for="item in bizData.basalTypeData" :value="item.value" :label="item.label" :key="item.value"></el-option>
              </el-select>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balInterHighOs">
              <el-input v-model="dataForm.balInterHighOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balInterDistanceOs">
              <el-input v-model="dataForm.balInterDistanceOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="pupilHeightOs">
              <el-input v-model="dataForm.pupilHeightOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="balVaOs">
              <el-input v-model="dataForm.balVaOs"></el-input>
            </el-form-item>
          </td>
          <td>
            <el-form-item prop="addOs">
              <el-input v-model="dataForm.addOs"></el-input>
            </el-form-item>
          </td>
        </tr>
      </table>


    <el-row class="bg-row" style="margin-top: 20px;">
      <el-form-item label="双眼平衡方法">
        <el-select v-model="dataForm.doubleBalanceWay">
          <el-option v-for="item in bizData.doubleBalanceWayData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="双眼终点红/绿试验">
        <el-select v-model="dataForm.doubleBalanceRg">
          <el-option v-for="item in bizData.doubleBalanceRgData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
    </el-row>
    <div style="position: fixed;bottom: 0;left: 0;right: 0;height: 45px;background-color: #d2d9db;display: flex;align-items: center;justify-content: flex-end;padding: 0 40px;">
      <el-button type="primary" @click="refractiveFormSubmit" v-prevent-re-click>保 存</el-button>
    </div>
    <!-- <el-row style="margin: 15px;float: right;">
      <el-button size="medium" type="primary" @click="refractiveFormSubmit" v-prevent-re-click>保 存</el-button>
    </el-row> -->
    <!-- 弹窗，查询顾客 -->
    <search-customer v-if="searchCustomerVisible" ref="searchCustomer" @refreshForm="getCustomerData"></search-customer>
    <!-- 弹窗，顾客详情 -->
    <detail-customer v-if="detailCustomerVisible" ref="detailCustomer"></detail-customer>
  </el-form>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { filterParams } from '@/util/tools'
  import { PostGlass } from '@/util/validate'
  import * as check from '@/util/check/check'
  import { addChkOptometryBasic,getChkOptometryBasic, addCheckRefractive, getCheckRefractive } from '@/api/admin/optometry/optometry'
  import { getPreCheck } from '@/api/admin/optometry/optometry'

  import SearchCustomer from '@/components/business/customer-search'
  import DetailCustomer from '@/views/eims/customer/detail'

  export default {
    data() {
      return {
        visible: false,
        activeName: 'second',
        searchCustomerVisible: '',
        detailCustomerVisible: '',
        id: '',
        checkData: {
          checkNumber: '',
          checkDate: '',
          checker: '',
        },
        chkDatas: [],
        customerData: {
          customerCard: '',
          id: '',
          name: '',
          gender: '',
          birthDay: '',
          telPhone: '',
          cardType: '',
          integral: ''
        },
        checkList: [],
        goals: '',
        optOptions: [
          { value: "1", label: '远用' },
          { value: "2", label: '近用' },
          { value: "3", label: '隐形' },
          { value: "4", label: '渐进/双光' },
          { value: "5", label: '中用' },
          { value: "6", label: '角膜塑形' },
          { value: "7", label: '视觉训练' },
        ],
        glassesType: '',
        glassesTypeOption: [
          {value: '1', label: '无'},
          {value: '2', label: '框架'},
          {value: '3', label: '隐形眼镜'},
        ],
        estimate: [],
        glassTypes: [],
        touchGlass: [],
        trainTypes: [],
        dataForm: {
          checkDate:'',
          checker:'',
          doctorsay: '',
          goals: '',
          chkOptometryList: [],
          taketype: '',
          secCheckDate: '',
          leadingEye: '',       //  主导眼
          nakedOd: '',          //  裸眼视力-右
          nakedOs: '',          //  裸眼视力-左
          diffusePupil: '1',    //  验光--验光方式
          checkBallGlassOd: '', //  验光--球镜-右
          checkBallGlassOs: '', //  验光--球镜-左
          checkPostGlassOd: '', //  验光--柱镜-右
          checkPostGlassOs: '', //  验光--柱镜-左
          checkAxesOd: '',      //  验光--轴向-右
          checkAxesOs: '',      //  验光--轴向-左

          testBallGlassOd: '',  //  试镜--球镜-右
          testBallGlassOs: '',  //  试镜--球镜-左
          testPostGlassOd: '',  //  试镜--柱镜-右
          testPostGlassOs: '',  //  试镜--柱镜-左
          testAxesOd: '',       //  试镜--轴向-右
          testAxesOs: '',       //  试镜--轴向-左
          testVaOd: '',         //  试镜--VA-右
          testVaOs: '',         //  试镜--VA-左

          oaBallGlassOd: '',    //  主观屈光--球镜-右
          oaBallGlassOs: '',    //  主观屈光--球镜-左
          oaPostGlassOd: '',    //  主观屈光--柱镜-右
          oaPostGlassOs: '',    //  主观屈光--柱镜-左
          oaAxesOd: '',         //  主观屈光--轴向-右
          oaAxesOs: '',         //  主观屈光--轴向-左
          oaVaOd: '',           //  主观屈光--VA-右
          oaVaOs: '',           //  烛光屈光--VA-左

          balBallGlassOd: '',   //  眼平衡--球镜-右
          balBallGlassOs: '',   //  眼平衡--球镜-左
          balPostGlassOd: '',   //  眼平衡--柱镜-右
          balPostGlassOs: '',   //  眼平衡--柱镜-左
          balAxesOd: '',        //  眼平衡--轴向-右
          balAxesOs: '',        //  眼平衡--轴向-左
          balArriseGlassOd: '', //  眼平衡--三棱镜-右
          balArriseGlassOs: '', //  眼平衡--三棱镜-左
          balBasisOd: '',       //  眼平衡--基底-右
          balBasisOs: '',       //  眼平衡--基底-左
          balInterHighOd: '',   //  眼平衡--远用瞳距-右
          balInterHighOs: '',   //  眼平衡--远用瞳距-左
          balInterDistanceOd: '', //  眼平衡--近用瞳距-右
          balInterDistanceOs: '', //  眼平衡--近用瞳距-左
          pupilHeightOd: '',    //  眼平衡--瞳高-右
          pupilHeightOs: '',    //  眼平衡--瞳高-左
          balVaOd: '',          //  眼平衡--VA-右
          balVaOs: '',          //  眼平衡--VA-左
          addOd: '',            //  眼平衡--ADD-右
          addOs: '',            //  眼平衡--ADD-左

          doubleBalanceWay: '', //  双眼平衡方法
          doubleBalanceRg: '',  //  双眼终点红/绿实验
        },

        dataRule: {
          ballOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          ballOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          postOd: [
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          postOs: [
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          axesOd: [
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          axesOs: [
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          ballOda:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          ballOsa:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          postOda: [
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          postOsa: [
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          axesOda: [
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          axesOsa: [
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],

          // 体格检查
          checkBallGlassOd: [{ required: true, validator: this.checkBallGlassOd, trigger: 'change' }],
          checkBallGlassOs: [{ required: true, validator: this.checkBallGlassOs, trigger: 'change' }],
          checkPostGlassOd: [{ required: true, validator: this.checkPostGlass, trigger: 'change' }],
          checkPostGlassOs: [{ required: true, validator: this.checkPostGlass, trigger: 'change' }],
          checkAxesOd: [{ required: true, validator: this.checkAxesOd, trigger: 'change' }],
          checkAxesOs: [{ required: true, validator: this.checkAxesOs, trigger: 'change' }],

          // 屈光检查
          checkBallGlassOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          checkPostGlassOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          checkAxesOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],

          testBallGlassOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          testPostGlassOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          testAxesOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          checkBallGlassOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          checkPostGlassOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          checkAxesOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          testBallGlassOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          testPostGlassOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          testAxesOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],

          oaBallGlassOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          oaPostGlassOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          oaAxesOd:[
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          oaBallGlassOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          oaPostGlassOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' },
          ],
          oaAxesOs:[
            { required: false, trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],

          balBallGlassOd: [
            { required: true,message: '球镜不能为空', trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          balBallGlassOs: [
            { required: true,message: '球镜不能为空', trigger: 'blur' },
            { validator: check.checkBallGlass, trigger: 'blur' },
          ],
          balPostGlassOd: [
            { required: true,message: '柱镜不能为空', trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' }
          ],
          balPostGlassOs: [
            { required: true,message: '柱镜不能为空', trigger: 'blur' },
            { validator: check.checkPostGlass, trigger: 'blur' }
          ],
          balAxesOd: [
            { required: true,message: '轴向不能为空', trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
          balAxesOs: [
            { required: true,message: '轴向不能为空', trigger: 'blur' },
            { validator: check.checkAxes, trigger: 'blur' }
          ],
        }
      }
    },
    components:{
      SearchCustomer,
      DetailCustomer
    },
    computed: {
      ...mapGetters(['permissions', 'bizData', 'userInfo', 'isCollapse'])
    },
    methods: {
      init(data) {
        this.visible = true
        this.checkData = data.checkData
        this.customerData = data.customer
        this.id = data.id
        for(let key in this.dataForm){
          if(key == 'chkOptometryList'){
            this.dataForm[key] = []
          }else{
            this.dataForm[key] = ''
          }
        }

        this.$nextTick(() => {
          if(this.id){
            getCheckRefractive(this.id).then(result => {
              let resultData = result.data.data
              if(resultData){
                this.dataForm = resultData
              }
            })
          }else{
            getPreCheck(this.customerData.id).then(response => {
              if(response.data.code == '0'){
                  if(response.data.data.id){
                    let responseData = response.data.data
                    this.$set(this.dataForm,'height',responseData.height)
                    this.$set(this.dataForm,'weight',responseData.weight)
                    this.$set(this.dataForm,'temperature',responseData.temperature)

                    this.$set(this.dataForm,'ballOd',responseData.hisBallOd)
                    this.$set(this.dataForm,'ballOs',responseData.hisBallOs)
                    this.$set(this.dataForm,'postOd',responseData.hisPostOd)
                    this.$set(this.dataForm,'postOs',responseData.hisPostOs)
                    this.$set(this.dataForm,'axesOd',responseData.hisAxesOd)
                    this.$set(this.dataForm,'axesOs',responseData.hisAxesOs)

                    this.$set(this.dataForm,'oaBallGlassOd',responseData.mainBallOd)
                    this.$set(this.dataForm,'oaBallGlassOs',responseData.mainBallOs)
                    this.$set(this.dataForm,'oaPostGlassOd',responseData.mainPostOd)
                    this.$set(this.dataForm,'oaPostGlassOs',responseData.mainPostOs)
                    this.$set(this.dataForm,'oaAxesOd',responseData.mainAxesOd)
                    this.$set(this.dataForm,'oaAxesOs',responseData.mainAxesOs)
                  }
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      openDialog(name) {
        switch (name) {
          case 'customer':
            this.searchCustomerVisible = true
            this.$nextTick(() => {
              this.$refs.searchCustomer.init()
            })
            break;
          case 'customerDetail':
            this.detailCustomerVisible = true
            this.$nextTick(() => {
              this.$refs.detailCustomer.init(this.customerData.id, '会员详细')
            })
            break;
        }

      },
      //  获取客户信息
      getCustomerData(data) {
        this.customerData = data
      },
      refractiveFormSubmit() {
        this.$refs['refractiveForm'].validate((valid) => {
          if (valid) {
            if(!this.id){
              let customerParams = { personId: this.customerData.id, customerName: this.customerData.name,chkNumber: this.checkData.checkNumber }
              addChkOptometryBasic(customerParams).then(result => {
                this.id = result.data.data
                this.$emit('addBasic',result.data.data)
              })
            }else{
              this.$emit('addBasic',this.id)
            }
          }
        })
      },
      saveRefractive(data){
        let params1 = {
          optometryBasicId: data,
          chkNumber: this.checkData.checkNumber,
          personId: this.customerData.id
        }
        let params2 = { ...this.dataForm }
        console.log(params2)
        addCheckRefractive(Object.assign(filterParams(params2), params1)).then(result => {
          this.$message.success('添加屈光检查成功')
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .el-form-item__content {
    width: calc(100% - 80px);
  }

  .bg-row {
    // background-color: #cadee8;
    padding-left: 15px;
    padding-top: 5px;
  }

  .width-125 {
    width: 125px;
  }

  .miui-table {
    width: 100%;
    margin: 10px 0;
    background-color: #b1e2ec3b;

    tr th {
      background-color: #f4f5f7;
    }

    tr th,
    tr td {
      padding: 10px 8px;
      border: solid 1px #e7e7e7;
      text-align: center;
    }

    .miui-table-header td {
      background-color: #7898a8;
      color: #fff;
    }

    .miui-table-tbody {
      background-color: #cadee8;
    }
  }
</style>
